/*

Boost Software License - Version 1.0 - August 17th, 2003

Permission is hereby granted, free of charge, to any person or organization
obtaining a copy of the software and accompanying documentation covered by
this license (the "Software") to use, reproduce, display, distribute,
execute, and transmit the Software, and to prepare derivative works of the
Software, and to permit third-parties to whom the Software is furnished to
do so, all subject to the following:

The copyright notices in the Software and this entire statement, including
the above license grant, this restriction and the following disclaimer,
must be included in all copies of the Software, in whole or in part, and
all derivative works of the Software, unless such copies or derivative
works are solely in the form of machine-executable object code generated by
a source language processor.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT
SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE
FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

*/
module derelict.pq.functions;

private {
    import std.stdio;
    import derelict.pq.types;
}

extern(C) nothrow
{
    /* Asynchronous (non-blocking) */
    alias PGconn* function(char* connInfo) da_PQconnectStart;
    alias PGconn* function(char** keywords, char** values, int expand_dbname) da_PQconnectStartParams;
    alias PostgresPollingStatusType function(PGconn* conn) da_PQconnectPoll;
    /* Synchronous (blocking) */
    alias PGconn* function(immutable char* connInfo) da_PQconnectdb;
    alias PGconn* function(char** keywords, char** values, int expand_dbname) da_PQconnectdbParams;
    alias PGconn* function(char* pghost, char* pgport, char* pgoptions, char* pgtty, char* dbName, char* login, char* pwd) da_PQsetdbLogin;

    alias void function(PGconn* conn) da_PQfinish;

    alias PQconninfoOption* function() da_PQconndefaults;
    alias PQconninfoOption* function(char* conninfo, char** errmsg) da_PQconninfoParse;
    alias PQconninfoOption* function(PGconn* conn) da_PQconninfo;
    alias void function(PQconninfoOption* connOptions) da_PQconninfoFree;

    alias int function(PGconn* conn) da_PQresetStart;
    alias PostgresPollingStatusType function(PGconn*) da_PQresetPoll;
    alias void function(PGconn* conn) da_PQreset;

    alias PGcancel* function(PGconn* conn) da_PQgetCancel;
    alias void function(PGcancel* cancel) da_PQfreeCancel;
    alias int function(PGcancel* cancel, char* errbuf, int errbufsize) da_PQcancel;
    alias int function(PGconn* conn) da_PQrequestCancel;

    alias char* function(PGconn* conn) da_PQdb;
    alias char* function(PGconn* conn) da_PQuser;
    alias char* function(PGconn* conn) da_PQpass;
    alias char* function(PGconn* conn) da_PQhost;
    alias char* function(PGconn* conn) da_PQport;
    alias char* function(PGconn* conn) da_PQtty;
    alias char* function(PGconn* conn) da_PQoptions;
    alias ConnStatusType function(PGconn* conn) da_PQstatus;

    alias PGTransactionStatusType function(PGconn* conn) da_PQtransactionStatus;
    alias char* function(PGconn* conn, char* paramName) da_PQparameterStatus;
    alias int function(PGconn* conn) da_PQprotocolVersion;
    alias int function(PGconn* conn) da_PQserverVersion;
    alias char* function(PGconn* conn) da_PQerrorMessage;
    alias int function(PGconn* conn) da_PQsocket;
    alias int function(PGconn* conn) da_PQbackendPID;
    alias int function(PGconn* conn) da_PQconnectionNeedsPassword;
    alias int function(PGconn* conn) da_PQconnectionUsedPassword;
    alias int function(PGconn* conn) da_PQclientEncoding;
    alias int function(PGconn* conn, char* encoding) da_PQsetClientEncoding;

    alias void* function(PGconn* conn) da_PQgetssl;
    alias void function(int do_init) da_PQinitSSL;
    alias void function(int do_ssl, int do_crypto) da_PQinitOpenSSL;

    alias PGVerbosity function(PGconn* conn, PGVerbosity verbosity) da_PQsetErrorVerbosity;
    alias void function(PGconn* conn, FILE* debug_port) da_PQtrace;
    alias void function(PGconn* conn) da_PQuntrace;

    alias PQnoticeReceiver function(PGconn* conn, PQnoticeReceiver proc, void* arg) da_PQsetNoticeReceiver;
    alias PQnotcieProcessor function(PGconn* conn, PQnotcieProcessor proc, void* arg) da_PQsetNoticeProcessor;

    alias pgthreadlock_t function(pgthreadlock_t newhandler) da_PQregisterThreadLock;
    /* Simple synchronous query */
    alias PGresult* function(PGconn* conn, const(char)* query) da_PQexec;
    alias PGresult* function(PGconn* conn, const(char)* command, int nParams, Oid* paramTypes, const(ubyte)** paramValues, int* paramLengths, int* paramFormats, int resultFormat) da_PQexecParams;
    alias PGresult* function(PGconn* conn, char* stmtName, char* query, int nParams, Oid* paramTypes) da_PQprepare;
    alias PGresult* function(PGconn* conn, char* stmtName, int nParams, char** paramValues, int* paramFormats, int resultFormat) da_PQexecPrepared;
    alias int function(PGconn* conn, const(char)* query) da_PQsendQuery;
    alias int function(PGconn* conn, const(char)* command, int nParams, Oid* paramTypes, const(ubyte)** paramValues, int* paramLengths, int* paramFormats, int resultFormat) da_PQsendQueryParams;
    alias int function(PGconn* conn, char* stmtName, char* query, int nParams, Oid* paramTypes) da_PQsendPrepare;
    alias int function(PGconn* conn, char* stmtName, int nParams, char** paramValues, int* paramLengths, int* paramFormats, int resultFormat) da_PQsendQueryPrepared;
    alias int function(PGconn* conn) da_PQsetSingleRowMode;
    alias PGresult* function(PGconn* conn) da_PQgetResult;
    /* Routines for managing an asynchronous query */
    alias int function(PGconn* conn) da_PQisBusy;
    alias int function(PGconn* conn) da_PQconsumeInput;
    /* LISTEN/NOTIFY support */
    alias immutable (PGnotify)* function(PGconn* conn) da_PQnotifies;
    /* Routines for copy in/out */
    alias int function(PGconn* conn, char* buffer, int nbytes) da_PQputCopyData;
    alias int function(PGconn* conn, char* errormsg) da_PQputCopyEnd;
    alias int function(PGconn* conn, char** buffer, int async) da_PQgetCopyData;
    /* Deprecated routines for copy in/out */
    alias int function(PGconn* conn, char* string, int length) da_PQgetline;
    alias int function(PGconn* conn, char* string) da_PQputline;
    alias int function(PGconn* conn, char* buffer, int bufsize) da_PQgetlineAsync;
    alias int function(PGconn* conn, char* buffer, int nbytes) da_PQputnbytes;
    alias int function(PGconn* conn) da_PQendcopy;
    /* Set blocking/nonblocking connection to the backend */
    alias int function(PGconn* conn, int arg) da_PQsetnonblocking;
    alias int function(PGconn* conn) da_PQisnonblocking;
    alias int function() da_PQisthreadsafe;
    alias PGPing function(char* conninfo) da_PQping;
    alias PGPing function(char** keywords, char** values, int expand_dbname) da_PQpingParams;

    alias int function(PGconn* conn) da_PQflush;
    /* Accessor functions for PGresult objects */
    alias PGresult* function(PGconn* conn, int fnid, int* result_buf, int* result_len, int result_is_int, PQArgBlock* args, int nargs) da_PQfn;
    alias ExecStatusType function(const(PGresult)* res) da_PQresultStatus;
    alias char* function(ExecStatusType status) da_PQresStatus;
    alias char* function(const(PGresult)* res) da_PQresultErrorMessage;
    alias char* function(PGresult* res, int fieldcode) da_PQresultErrorField;
    alias int function(const(PGresult)* res) da_PQntuples;
    alias int function(const(PGresult)* res) da_PQnfields;
    alias int function(PGresult* res) da_PQbinaryTuples;
    alias char* function(PGresult* res, int field_num) da_PQfname;
    alias int function(const(PGresult)* res, immutable char* field_name) da_PQfnumber;
    alias Oid function(PGresult* res, int field_num) da_PQftable;
    alias int function(PGresult* res, int field_num) da_PQftablecol;
    alias valueFormat function(const(PGresult)* res, int field_num) da_PQfformat;
    alias Oid function(const(PGresult)* res, int field_num) da_PQftype;
    alias int function(PGresult* res, int field_num) da_PQfsize;
    alias int function(PGresult* res, int field_num) da_PQfmod;
    alias char* function(const(PGresult)* res) da_PQcmdStatus;
    alias char* function(PGresult* res) da_PQoidStatus;
    alias Oid function(PGresult* res) da_PQoidValue;
    alias char* function(PGresult* res) da_PQcmdTuples;
    alias immutable(ubyte)* function(const(PGresult)* res, int tup_num, int field_num) da_PQgetvalue;
    alias int function(const(PGresult)* res, int tup_num, int field_num) da_PQgetlength;
    alias int function(const(PGresult)* res, int tup_num, int field_num) da_PQgetisnull;
    alias int function(PGresult* res) da_PQnparams;
    alias Oid function(PGresult* res, int param_num) da_PQparamtype;
    /* Describe prepared statements and portals */
    alias PGresult* function(PGconn* conn, char* stmt) da_PQdescribePrepared;
    alias PGresult* function(PGconn* conn, char* portal) da_PQdescribePortal;
    alias int function(PGconn* conn, char* stmt) da_PQsendDescribePrepared;
    alias int function(PGconn* conn, char* portal) da_PQsendDescribePortal;

    alias void function(const(PGresult)* res) da_PQclear;
    alias void function(void* ptr) da_PQfreemem;
    /* Create and manipulate PGresults */
    alias PGresult* function(PGconn* conn, ExecStatusType status) da_PQmakeEmptyPGresult;
    alias PGresult* function(const(PGresult)* src, int flags) da_PQcopyResult;
    alias int function(PGresult* res, int numAttributes, PGresAttDesc* attDescs) da_PQsetResultAttrs;
    alias void* function(PGresult* res, size_t nBytes) da_PQresultAlloc;
    alias int function(PGresult* res, int tup_num, int field_num, char* value, int len) da_PQsetvalue;
    /* Quoting strings before inclusion in queries. */
    alias size_t function(PGconn* conn, char* to, char* from, size_t length, int* error) da_PQescapeStringConn;
    alias char* function(PGconn* conn, const(char)* str, size_t len) da_PQescapeLiteral;
    alias char* function(PGconn* conn, const(char)* str, size_t length) da_PQescapeIdentifier;
    alias ubyte* function(PGconn* conn, ubyte* from, size_t from_length, size_t* to_length) da_PQescapeByteaConn;
    alias ubyte* function(ubyte* strtext, size_t* retbuflen) da_PQunescapeBytea;
    /* These forms are deprecated! */
    alias size_t function(char* to, char* from, size_t length) da_PQescapeString;
    alias ubyte* function(ubyte* from, size_t from_length, size_t* to_length) da_PQescapeBytea;

    alias void function(FILE* fout, PGresult* res, PQprintOpt* ps) da_PQprint;
    alias void function(PGresult* res, FILE* fp, int fillAlign, char* fieldSep, int printHeader, int quiet) da_PQdisplayTuples;
    alias void function(PGresult* res, FILE* fout, int printAttName, int terseOutput, int width) da_PQprintTuples;
    /* Large-object access routines */
    alias int function(PGconn* conn, Oid lobjId, int mode) da_lo_open;
    alias int function(PGconn* conn, int fd) da_lo_close;
    alias int function(PGconn* conn, int fd, char* fuf, size_t len) da_lo_read;
    alias int function(PGconn* conn, int fd, const(char)* buf, size_t len) da_lo_write;
    alias int function(PGconn* conn, int fd, int offset, int whence) da_lo_lseek;
    alias pg_int64 function(PGconn* conn, int fd, pg_int64 offset, int whence) da_lo_lseek64;
    alias Oid function(PGconn* conn, int mode) da_lo_creat;
    alias Oid function(PGconn* conn, Oid lobjId) da_lo_create;
    alias int function(PGconn* conn, int fd) da_lo_tell;
    alias pg_int64 function(PGconn* conn, int fd) da_lo_tell64;
    alias int function(PGconn* conn, int fd, size_t len) da_lo_truncate;
    alias int function(PGconn* conn, int fd, pg_int64 len) da_lo_truncate64;
    alias int function(PGconn* conn, Oid lobjId) da_lo_unlink;
    alias Oid function(PGconn* conn, const(char)* filename) da_lo_import;
    alias Oid function(PGconn* conn, const(char)* filename, Oid lobjId) da_lo_import_with_oid;
    alias int function(PGconn* conn, Oid lobjId, const(char)* filename) da_lo_export;

    alias int function() da_PQlibVersion;
    alias int function(char* s, int encoding) da_PQmblen;
    alias int function(char* s, int encoding) da_PQdsplen;
    alias int function() da_PQenv2encoding;
    alias char* function(char* passwd, char* user) da_PQencryptPassword;

    alias int function(const(char)* name) da_pg_char_to_encoding;
    alias const(char)* function(int encoding) da_pg_encoding_to_char;
    alias int function(int encoding) da_pg_valid_server_encoding_id;

    alias int function(PGconn* conn, PGEventProc proc, immutable char* name, void* passThrough) da_PQregisterEventProc;
    alias int function(PGconn* conn, PGEventProc proc, void* data) da_PQsetInstanceData;
}

__gshared
{
    da_PQconnectStart PQconnectStart;
    da_PQconnectStartParams PQconnectStartParams;
    da_PQconnectPoll PQconnectPoll;
    da_PQconnectdb PQconnectdb;
    da_PQconnectdbParams PQconnectdbParams;
    da_PQsetdbLogin PQsetdbLogin;
    da_PQfinish PQfinish;
    da_PQconndefaults PQconndefaults;
    da_PQconninfoParse PQconninfoParse;
    da_PQconninfo PQconninfo;
    da_PQconninfoFree PQconninfoFree;
    da_PQresetStart PQresetStart;
    da_PQresetPoll PQresetPoll;
    da_PQreset PQreset;
    da_PQgetCancel PQgetCancel;
    da_PQfreeCancel PQfreeCancel;
    da_PQcancel PQcancel;
    da_PQrequestCancel PQrequestCancel;
    da_PQdb PQdb;
    da_PQuser PQuser;
    da_PQpass PQpass;
    da_PQhost PQhost;
    da_PQport PQport;
    da_PQtty PQtty;
    da_PQoptions PQoptions;
    da_PQstatus PQstatus;
    da_PQtransactionStatus PQtransactionStatus;
    da_PQparameterStatus PQparameterStatus;
    da_PQprotocolVersion PQprotocolVersion;
    da_PQserverVersion PQserverVersion;
    da_PQerrorMessage PQerrorMessage;
    da_PQsocket PQsocket;
    da_PQbackendPID PQbackendPID;
    da_PQconnectionNeedsPassword PQconnectionNeedsPassword;
    da_PQconnectionUsedPassword PQconnectionUsedPassword;
    da_PQclientEncoding PQclientEncoding;
    da_PQsetClientEncoding PQsetClientEncoding;
    da_PQgetssl PQgetssl;
    da_PQinitSSL PQinitSSL;
    da_PQinitOpenSSL PQinitOpenSSL;
    da_PQsetErrorVerbosity PQsetErrorVerbosity;
    da_PQtrace PQtrace;
    da_PQuntrace PQuntrace;
    da_PQsetNoticeReceiver PQsetNoticeReceiver;
    da_PQsetNoticeProcessor PQsetNoticeProcessor;
    da_PQregisterThreadLock PQregisterThreadLock;
    da_PQexec PQexec;
    da_PQexecParams PQexecParams;
    da_PQprepare PQprepare;
    da_PQexecPrepared PQexecPrepared;
    da_PQsendQuery PQsendQuery;
    da_PQsendQueryParams PQsendQueryParams;
    da_PQsendPrepare PQsendPrepare;
    da_PQsendQueryPrepared PQsendQueryPrepared;
    da_PQsetSingleRowMode PQsetSingleRowMode;
    da_PQgetResult PQgetResult;
    da_PQisBusy PQisBusy;
    da_PQconsumeInput PQconsumeInput;
    da_PQnotifies PQnotifies;
    da_PQputCopyData PQputCopyData;
    da_PQputCopyEnd PQputCopyEnd;
    da_PQgetCopyData PQgetCopyData;
    da_PQgetline PQgetline;
    da_PQputline PQputline;
    da_PQgetlineAsync PQgetlineAsync;
    da_PQputnbytes PQputnbytes;
    da_PQendcopy PQendcopy;
    da_PQsetnonblocking PQsetnonblocking;
    da_PQisnonblocking PQisnonblocking;
    da_PQisthreadsafe PQisthreadsafe;
    da_PQping PQping;
    da_PQpingParams PQpingParams;
    da_PQflush PQflush;
    da_PQfn PQfn;
    da_PQresultStatus PQresultStatus;
    da_PQresStatus PQresStatus;
    da_PQresultErrorMessage PQresultErrorMessage;
    da_PQresultErrorField PQresultErrorField;
    da_PQntuples PQntuples;
    da_PQnfields PQnfields;
    da_PQbinaryTuples PQbinaryTuples;
    da_PQfname PQfname;
    da_PQfnumber PQfnumber;
    da_PQftable PQftable;
    da_PQftablecol PQftablecol;
    da_PQfformat PQfformat;
    da_PQftype PQftype;
    da_PQfsize PQfsize;
    da_PQfmod PQfmod;
    da_PQcmdStatus PQcmdStatus;
    da_PQoidStatus PQoidStatus;
    da_PQoidValue PQoidValue;
    da_PQcmdTuples PQcmdTuples;
    da_PQgetvalue PQgetvalue;
    da_PQgetlength PQgetlength;
    da_PQgetisnull PQgetisnull;
    da_PQnparams PQnparams;
    da_PQparamtype PQparamtype;
    da_PQdescribePrepared PQdescribePrepared;
    da_PQdescribePortal PQdescribePortal;
    da_PQsendDescribePrepared PQsendDescribePrepared;
    da_PQsendDescribePortal PQsendDescribePortal;
    da_PQclear PQclear;
    da_PQfreemem PQfreemem;
    da_PQmakeEmptyPGresult PQmakeEmptyPGresult;
    da_PQcopyResult PQcopyResult;
    da_PQsetResultAttrs PQsetResultAttrs;
    da_PQresultAlloc PQresultAlloc;
    da_PQsetvalue PQsetvalue;
    da_PQescapeStringConn PQescapeStringConn;
    da_PQescapeLiteral PQescapeLiteral;
    da_PQescapeIdentifier PQescapeIdentifier;
    da_PQescapeByteaConn PQescapeByteaConn;
    da_PQunescapeBytea PQunescapeBytea;
    da_PQescapeString PQescapeString;
    da_PQescapeBytea PQescapeBytea;
    da_PQprint PQprint;
    da_PQdisplayTuples PQdisplayTuples;
    da_PQprintTuples PQprintTuples;
    da_lo_open lo_open;
    da_lo_close lo_close;
    da_lo_read lo_read;
    da_lo_write lo_write;
    da_lo_lseek lo_lseek;
    da_lo_lseek64 lo_lseek64;
    da_lo_creat lo_creat;
    da_lo_create lo_create;
    da_lo_tell lo_tell;
    da_lo_tell64 lo_tell64;
    da_lo_truncate lo_truncate;
    da_lo_truncate64 lo_truncate64;
    da_lo_unlink lo_unlink;
    da_lo_import lo_import;
    da_lo_import_with_oid lo_import_with_oid;
    da_lo_export lo_export;
    da_PQlibVersion PQlibVersion;
    da_PQmblen PQmblen;
    da_PQdsplen PQdsplen;
    da_PQenv2encoding PQenv2encoding;
    da_PQencryptPassword PQencryptPassword;
    da_pg_char_to_encoding pg_char_to_encoding;
    da_pg_encoding_to_char pg_encoding_to_char;
    da_pg_valid_server_encoding_id pg_valid_server_encoding_id;
    da_PQregisterEventProc PQregisterEventProc;
    da_PQsetInstanceData PQsetInstanceData;
}
